import { Component, OnInit } from '@angular/core';
import { AxiosService } from '../../axios.service';
import { LocalStorageService } from 'src/app/myService/local-storage.service';
import { Router } from '@angular/router';
import { ActivatedRoute } from '@angular/router';
import { data } from 'jquery';
import { THIS_EXPR } from '@angular/compiler/src/output/output_ast';
import { log } from 'console';


@Component({
  selector: 'app-emp-process',
  templateUrl: './emp-process.component.html',
  styleUrls: ['./emp-process.component.scss']
})
export class EmpProcessComponent implements OnInit {

  isLoading;

  //所有工单数据
  public tempData = [];

  public listOfData = [];//工单文件区数据

  fileInfom;//显示工单对应的文件信息
  isOkLoadingfileInfom;

  public fileList;//选择要上传的文件
  public workName;
  uploader;
  fileName;//文件名
  workerName;//工件名
  link;
  workOrder;//上传对应的工单号
  sheet_order;//工件上传

  isSendVisible;//送出工件
  isSendOkLoading;

  isFileVisible;//删除文件信息
  isFileOkLoading;
  id;//文件信息id
  tdbz;
  tdbz2;

  public unionorder: any;//工单号,
  public newValue: any;//"新值"
  name;//"表中栏位名称"

  addRemark1;//编辑设计备注
  addRemark2;//编辑设计备注

  isOkLoadingRemark;
  isOkLoadingRemark2;
  designRemark;
  designRemark2;
  wor;
  zdcc;

  splitJudge: string = ',';

  // 接收要修改的数据
  updateData;

  first: any;//首个19码
  tail: any;//结尾19码
  uploadData; // 上传数据

  public workData = [];
  //意同workData
  public dataWork = [];
  public selCNCData = [];

  isShow = [];
  btnStop = [];
  btnStart = [];

  value;//计时时间值
  totalTime;//数据库中的时间
  time;//页面的时间
  recordRowClick = -1;

  //其他备注
  addOtherRemark;
  isOkLoadingOthRemark;
  RemarkValue;//备注框的值
  workKey;

  showWarning = {};//工件行显示退回图标
  showBigWarning;//工单行显示退回图标

  timeIndex = 0;
  hour;
  minutes;
  seconds;
  timeKey: any = [];

  unionKey;
  smallKey;
  timeDic = {};
  key3;//加工件  记录坐标位置
  xh;

  sfmtime = new Array;

  // 排工单数据
  paigongdanLiist = [];

  selectStatus = ["All",]
  dlyy;
  dlyynr;
  fileInfom2;
  imglist;
  dlyysz = [];
  listfd = [];
  fdkey;
  tdfdlist;
  addDlyy;
  dlyyadd;
  // 以下数据用于指派工程师后发送邮件
  engineerJobNo = [];
  engineerMail = [];
  mailParamsForSend = {
    "type": '',
    "WorkOrder": "",
    "factory": "",
    "name": "",
    "machine_type": "",
    "quantity": 0,
    "toolway": "",
    "delivery_date": "",
    "emp": [],
    "empAddress":[]
  };

  constructor(
    public axios: AxiosService,
    private storage: LocalStorageService,
    public activatedRoute: ActivatedRoute,
    private router: Router
  ) {
    this.activatedRoute.params.subscribe((data) => {
      if (data) {
        console.log("----------------------------\n", data)
        // this.nameTitle = data.name;
        // console.log(this.nameTitle)
      }
    })
  }

  ngOnInit(): void {
    //获取全部数据
    this.getAllData();
    //获取当前时间
    var date = new Date();
    var year = date.getFullYear();
    var month = date.getMonth() + 1;
    var day = date.getDate();
    var day2;
    var month2;
    if (month < 10) {
      month2 = "0" + month;
    } else {
      month2 = month;
    }
    if (day < 10) {
      day2 = "0" + day;
    } else {
      day2 = day;
    }
    var nowDate = year + "-" + month2 + "-" + day2;
    console.log(nowDate)
    this.axios.axiosPost("QueryCncInfo", { "status": "cncTime", "starttime": nowDate }).then((data) => {
      console.log(data)
      for (var i = 0; i < data["order"].length; i++) {
        this.selectStatus.push(data["order"][i].name + " ( " + data["order"][i].cncTime + " )")
      }
    })
  }

  //获取全部数据
  getAllData() {
    this.axios.axiosPost('QueryUnionOrder', { "stage": 2, "stageValue": 1 })
      .then((data) => {
        console.log(data)
        if (data) {
          // debugger
          this.sfmtime.splice(0, this.sfmtime.length)
          this.tempData = data['order'];
          this.storage.setStorageData('result', this.tempData);
          this.listfd = []
          // this.QueryWorkOrder();
          for (let i = 0; i < this.tempData.length; i++) {
            this.listfd.push(new Array)
            // 实际时间栏位把秒转为小时
            this.tempData[i].jiagong_shijian = Number(this.tempData[i].jiagong_shijian) / 3600;
            if (this.tempData[i].jiagong_shijian > 0.00) {
              this.tempData[i].jiagong_shijian = Math.floor((this.tempData[i].jiagong_shijian + 0.01) * 100) / 100;
            }
            var b = [];
            this.sfmtime.push(b);
          }
        }
      })
      .catch((err) => {
        console.log(err);
      })
  }
  downLoad2(infom) {
    console.log(infom)
    this.fileInfom2 = true;
    this.link = this.axios.domainTest1;
    if (infom.imagefile) {
      this.imglist = infom.imagefile.split(",")
    } else {
      this.imglist = [];
    }
  }
  CancelShow2() {
    this.fileInfom2 = false;
  }
  ShowOK2() {
    this.fileInfom2 = false;
  }
  //查询工单对应的工件信息
  QueryWorkOrder(key) {
    this.workKey = key;
    this.axios.axiosPost('QueryWorkOrder', {
      'unionorder': this.tempData[key].union_order, "status"
        : 2
    })
      .then((data) => {
        console.log(data)
        if (data['result'] === 'ok' && data['order'].length > 0) {
          //过滤标准件，只显示加工件
          let a = data['order'].filter((item, i) => { return item.type_flag != 0; })
          //只显示编程阶段送出的工件
          let b = a.filter((item, i) => { return item.status != 0; })
          this.workData[key] = b;
          this.dataWork = b;
          console.log(this.workData)
          this.sfmtime[key] = [];
          this.listfd[key] = new Array;
          for (var t = 0; t < this.workData[key].length; t++) {
            this.listfd[key].push(new Array)
            var sss = {
              zs: false, sj: "00:00:00", mp: false, jsq: "", ks: "", kg: false
            }
            this.sfmtime[key].push(sss)
          }
        }
      })
      .catch((err) => {
        console.log(err);
      })
    // }
  }

  //CNC机台选择
  selStatus(item) {
    item.checked = !item.checked;
    this.selCNC(item);
  }

  //筛选CNC机台
  selCNC(data) {
    // debugger
    console.log(data)
    // 选中
    if (data.checked) {
      const addCNC = this.dataWork.filter(res => res['cnc_name'] === data.select);
      this.selCNCData = this.selCNCData.concat(addCNC);
    }
    // 未选中
    if (!data.checked) {
      const deleteCNC = this.workData.filter(res => res['cnc_name'] === data.select);
      this.selCNCData = this.workData.filter(item => !deleteCNC.some(ele => ele['cnc_name'] === item['cnc_name']));
    }
    // this.workData = [];
    this.workData = this.selCNCData;
  }

  //点击设计备注
  addRemark(item) {
    this.addRemark1 = true;
    this.designRemark = item.machine_remark;
    this.updateData = item;


  }
  addRemark3(item) {
    this.updateData = item;
    this.axios.axiosPost("QueryBeizhuInfo").then((data) => {
      this.dlyy = data["order"]
      for (var i = 0; i < this.dlyy.length; i++) {
        this.dlyy[i].show = false
      }
      this.axios.axiosPost('QueryWorkOrder', { 'id': item.id }).then((data) => {
        this.addRemark2 = true;
        item = data["order"][0]
        console.log(item)
        if (item.machine_remark.split(",")) {
          this.designRemark = item.machine_remark;
          this.updateData = item;
          this.dlyysz = item.machine_remark.split(",");
          for (var i = 0; i < this.dlyysz.length; i++) {
            for (var y = 0; y < this.dlyy.length; y++) {
              if (this.dlyysz[i] == this.dlyy[y].name) {
                this.dlyy[y].show = true;
              }
            }
          }
        }
      })
    })

  }

  //确认添加设计备注
  addRemarkOk() {

    this.isOkLoadingRemark = true;
    this.addRemark1 = false;
    this.isOkLoadingRemark = false;

    this.axios.axiosPost('UpdateUnionOrder', { 'unionorder': this.updateData.union_order, 'name': 'machine_remark', 'newValue': this.designRemark })
      .then((data) => {
        if (data['result'] === 'ok') {
          this.getAllData();
        }
      })
  }


  //确认添加设计备注
  addRemarkOk2() {
    this.dlyysz = []
    for (var i = 0; i < this.dlyy.length; i++) {
      if (this.dlyy[i].show == true) {
        this.dlyysz.push(this.dlyy[i].name)
      }
    }
    this.dlyynr = this.dlyysz.join(",")
    this.addRemark2 = false;
    this.isOkLoadingRemark2 = false;
    for (var i = 0; i < this.tempData.length; i++) {
      if (this.updateData.union_order == this.tempData[i].union_order) {
        this.key3 = i;
      }
    }
    this.axios.axiosPost('UpdateWorkOrder', {
      'unionorder': this.updateData.union_order, 'workorder': this.updateData.b,
      'machine_remark': this.dlyynr
    }).then((data) => {
      if (data['result'] === 'ok') {
        console.log("刷新数据,第几个工单下的", this.key3)
        this.QueryWorkOrder(this.key3)
        this.CancelAddRemark2()
      }
    })
  }

  //取消添加设计备注
  CancelAddRemark() {
    this.addRemark1 = false;
  }
  //取消添加设计备注
  CancelAddRemark2() {
    this.addRemark2 = false;
    for (var i = 0; i < this.dlyy.length; i++) {
      this.dlyy[i].show = false
    }
  }
  bzclick(name) {
    console.log(name)
    console.log(this.dlyy)
    this.dlyysz = []
    for (var i = 0; i < this.dlyy.length; i++) {
      if (this.dlyy[i].show == true) {
        this.dlyysz.push(this.dlyy[i].name)
      }
    }
    this.dlyynr = this.dlyysz.join(",")
    console.log(this.dlyynr)
  }

  currentPageDataChange(qqq) {

  }
  //点击图标显示此工单的文件信息
  downLoad(infom) {
    console.log(infom)
    this.fileInfom = true;
    // this.updateData = infom;
    // debugger
    this.workOrder = infom.union_order;
    this.workerName = infom.name;
    this.workName = this.workOrder;
    this.sheet_order = infom.sheet_order;
    console.log(infom.name, this.workOrder)
    if (infom.name !== undefined) {
      this.axios.axiosPost('QueryWorkFiles', { 'unionorder': this.workOrder, 'workorder': infom.name })
        .then((data) => {
          console.log(data)
          if (data['result'] === 'ok') {
            this.listOfData = data['files'];
          }
        })
    } else if (infom.name === undefined) {
      this.axios.axiosPost('QueryWorkFiles', { 'unionorder': this.workOrder, 'workorder': this.sheet_order })
        .then((data) => {
          console.log(data)
          if (data['result'] === 'ok') {
            this.listOfData = data['files'];
          }
        })
    }
  }

  CancelShow() {
    this.fileInfom = false;
  }

  ShowOK() {
    this.isOkLoadingfileInfom = true;
    this.fileInfom = false;
    this.isOkLoadingfileInfom = false;
  }

  //上传文件
  Upload() {
    // debugger
    if (this.uploadData == null)
      return;
    console.log(this.workOrder, this.workerName)
    if (this.workerName !== undefined) {
      this.isLoading = true;
      this.axios.axiosPost('Upload', {
        'unionorder': this.workOrder, 'workorder': this.workerName,
        'filename': this.fileName.files[0]['name'], 'filedata': this.uploadData
      })
        .then((data) => {

          console.log(data)
          if (data['result'] === 'ok') {
            this.isLoading = false;
            alert("上传成功！")
            this.uploadData = null;
            this.axios.axiosPost('QueryWorkFiles', { 'unionorder': this.workOrder, 'workorder': this.workerName })
              .then((data) => {
                if (data['result'] === 'ok') {
                  this.listOfData = data['files'];
                }
              })

          } else {
            this.isLoading = false;
            alert(data["description"])
          }
        }).catch(function (err) {
          console.log(err)
        })
    } else if (this.workerName === undefined) {
      this.isLoading = true;
      this.axios.axiosPost('Upload', {
        'unionorder': this.workOrder, 'workorder': this.sheet_order,
        'filename': this.fileName.files[0]['name'], 'filedata': this.uploadData
      })
        .then((data) => {

          console.log(data)
          if (data['result'] === 'ok') {
            this.isLoading = false;
            alert("上传成功！")
            this.uploadData = null;
            this.axios.axiosPost('QueryWorkFiles', { 'unionorder': this.workOrder, 'workorder': this.sheet_order })
              .then((data) => {
                if (data['result'] === 'ok') {
                  this.listOfData = data['files'];
                }
              })

          } else {
            this.isLoading = false;
            alert(data["description"])
          }
        }).catch(function (err) {
          console.log(err)
        })
    }


  }

  //选择要上传的文件名
  openFile(event: any): void {
    // debugger
    this.fileName = event.target; //获取点击得到的对象
    const reader = new FileReader();
    reader.onload = (() => {
      if (reader.result) {
        this.uploadData = reader.result;
        console.log(reader.result);
      }
    });
    reader.readAsDataURL(this.fileName.files[0]);//将文件转为Base64格式
    console.log("hahahaahahahah\n", reader.result)
  }

  handleFileCancel() {
    this.isFileVisible = false;
  }

  //下载文件
  downLoadFile(data) {
    console.log(data)
    this.fileName = data.file_name;
    this.link = this.axios.domainTest1 + this.workName + '/' + this.fileName;
    console.log(this.fileName, this.link)
  }

  //删除文件信息
  showDelFile(data) {
    this.isFileVisible = true;
    console.log(data)
    this.id = data.id;
  }

  delFileOk() {
    this.isFileOkLoading = true;
    this.isFileVisible = false;
    this.isFileOkLoading = false;
    this.axios.axiosPost('DeleteWorkFile', { 'id': this.id })
      .then((data) => {
        console.log(data)
        if (data['result'] === 'ok') {
          let listData = this.listOfData.filter(res => res['id'] !== this.id)
          this.listOfData = listData;
        }
      })
  }


  //点击工单号显示CNC
  showCNC(item) {
    console.log(item)
    const data = {};
    data['union_order'] = item.union_order;
    data['from'] = "jg";
    console.log(data['union_order'])
    this.router.navigate(['/CNC', data])
    // {queryParams: {refersh: new Date().getTime()}}
  }

  //点击行显示计时器
  clickLine(bigkey, key, item2) {
    if (this.sfmtime[bigkey][key].mp == false) {
      this.sfmtime[bigkey][key].zs = true;
      this.sfmtime[bigkey][key].mp == true;
      if (item2) {
        console.log(item2);
        // console.log("开始");
        this.sfmtime[bigkey][key].jsq = setInterval(() => {
          this.sfmtime[bigkey][key].sj = this.timeof(new Date().getTime() - item2)
        }, 1000)
      }
      console.log(item2);
    }
  }

  //开始计时
  start(bigkey, key, item2) {
    if (this.sfmtime[bigkey][key].kg == false) {
      this.sfmtime[bigkey][key].kg = true;
      if (this.sfmtime[bigkey][key].sj == "00:00:00") {
        this.axios.axiosPost('UpdateWorkOrder', {
          'unionorder': item2.union_order, 'workorder': item2.sheet_order,
          'timestamp': new Date().getTime()
        }).then((data) => {
          console.log(data);
          if (data["result"] == "ok") {
            this.workData[bigkey][key].timestamp = new Date().getTime();
            this.clickLine(bigkey, key, new Date().getTime());
          }
        })

      } else {
        alert("已經開始計時了")
      }
      // this.sfmtime[bigkey][key].ks = new Date().getTime();
      // this.sfmtime[bigkey][key].jsq = setInterval(() => {
      //   this.sfmtime[bigkey][key].sj = this.timeof(new Date().getTime() - this.sfmtime[bigkey][key].ks)
      //   console.log("aaaa")
      // }, 1000)
    } else {
      alert("已經開始計時，請勿重復操作")
    }
  }



  //结束计时
  end(item, bigkey, key) {
    if (item.timestamp || this.sfmtime[bigkey][key].sj != "00:00:00") {
      clearInterval(this.sfmtime[bigkey][key].jsq)
      this.axios.axiosPost('AddWorkTime', { 'unionorder': item.union_order, "id": item.id, 'endtime': new Date().getTime(), "stage": 2 })
        .then((data) => {
          console.log(data)
          if (data['result'] === 'ok') {
            console.log("真棒");
            clearInterval(this.sfmtime[bigkey][key].jsq)
            this.sfmtime[bigkey][key].sj = "00:00:00";
            this.sfmtime[bigkey][key].mp = false;
            this.sfmtime[bigkey][key].kg = false;
            this.sfmtime[bigkey][key].zs = false;
            this.sfmtime[bigkey][key].ks = "";
            this.workData[bigkey][key].timestamp = "";
            console.log(this.workData[bigkey][key].timestamp);

            // this.QueryWorkOrder(bigkey)
          }
        })
    } else {
      alert("此工件未開始計時")
    }



  }
  timeof(data) {
    var s;
    var hours: number;
    // hours=parseInt((1000 % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
    hours = parseInt((data % (1000 * 60 * 60 * 24) / (1000 * 60 * 60)).toString())
    // parseInt((1000 % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60))
    // console.log(hours)
    var minutes = parseInt(((data % (1000 * 60 * 60)) / (1000 * 60)).toString());
    var seconds = parseInt(((data % (1000 * 60)) / 1000).toString());
    s = (hours < 10 ? ('0' + hours) : hours) + ':' + (minutes < 10 ? ('0' + minutes) : minutes) + ':' + (seconds < 10 ? ('0' + seconds) : seconds);
    // console.log(s)
    return s;
  }

  //结束页面生命周期
  ngOnDestroy(): void {

  }


  //退回工件
  return(item, key, key2) {
    if (item.timestamp == "") {
      this.wor = key;
      this.fdkey = key2;
      this.unionorder = item.union_order;
      this.workerName = item.sheet_order;
      console.log(item, this.workerName)
      this.addOtherRemark = true;
      this.tdfdlist = item;
      let index = item.remark.indexOf(this.storage.getStorageData('user').name)
      if (index === 0 && item['remark']) {
        this.RemarkValue = item.remark + '\n\n';
      } else {
        this.RemarkValue = this.storage.getStorageData('user').name + ':' + item.remark;
      }
      this.tdbz = this.RemarkValue;
      this.tdbz2 = item.remark;
    } else {
      alert("該工件未停止計時")
    }
  }

  //取消备注
  CancelRemark() {
    this.addOtherRemark = false;
  }

  //添加其他备注（退回）
  RemarkOk() {

    if (this.RemarkValue.length != 0) {
      console.log(this.tdbz)
      console.log(this.RemarkValue)
      console.log(typeof (this.RemarkValue))
      console.log(this.tdbz2)
      this.isOkLoadingOthRemark = true;
      this.addOtherRemark = false;
      this.isOkLoadingOthRemark = false;
      let content = '';
      content = this.RemarkValue;//姓名+内容
      console.log(content)
      this.axios.axiosPost("UpdateUnionOrder2", { 'unionorder': this.unionorder, "name1": "stage", "newValue1": 1, "stageValue": 1 }).then((data) => {
        console.log(data, "工单状态修改成功了,增加了编程的状态")
      })
      this.axios.axiosPost("UpdateUnionOrder2", { 'unionorder': this.unionorder, "name1": "zuzhuang_endtime", "newValue1": "", "name2": "ercijg_endtime", "newValue2": "", "name3": "jiagong_endtime", "newValue3": "", "name4": "biancheng_endtime", "newValue4": "" }).then((data) => {
        console.log(data, "取消组装,二次加工,加工，编程时间栏位,")
      })
      this.axios.axiosPost('UpdateWorkOrder', {
        'unionorder': this.unionorder, 'workorder': this.workerName, id: this.tdfdlist["id"], 'remark': content, 'status': 1
      })
        .then((data) => {
          console.log(data)
          if (data['result'] === 'ok') {
            this.axios.axiosPost('QueryWorkOrder', { 'unionorder': this.unionorder, "type": 1, "status": 2 }).then((data) => {
              console.log(data["order"].length)
              if (data["order"].length <= 0) {
                this.axios.axiosPost("UpdateUnionOrder2", { 'unionorder': this.unionorder, "name1": "stage", "newValue1": 1, "stageValue": 1, "newValue12": 2, "stageValue2": 0 }).then((data) => {
                  console.log(data, "工单状态修改成功了,取消了当前工单状态")
                  location.reload();
                })
              } else {
                this.axios.axiosPost("QueryCncDataSubOrder", { "unionorder": this.unionorder, "workorder": this.workerName, status: 2 }).then((data) => {
                  console.log(data);
                  if (data["result"] == "ok") {
                    console.log(data["result"])
                    console.log(data)
                    if (data["order"] == undefined || data["order"].length <= 0) {
                      this.QueryWorkOrder(this.wor);
                    } else {
                      this.QueryWorkOrder2(this.tdfdlist, this.wor, this.fdkey)
                    }
                  }
                })
              }
            })
          }
        })
        .catch((err) => {
          console.log(err);
        })
    } else {
      alert("請輸入退單備註")
    }
  }

  //送出按钮
  send(item, wor, a,itemBig) {
    console.log(item.timestamp);

    console.log('itemBig:\n'+JSON.stringify(itemBig) );
    
    if (item.timestamp == "") {
      this.isSendVisible = true;
      this.unionorder = item.union_order;
      this.workerName = item.sheet_order;
      this.xh = item.box;
      this.wor = wor;
      this.zdcc = item.bom_remark;
      this.paigongdanLiist = item;
      this.fdkey = a;

      // 准备邮件发送的参数
      this.mailParamsForSend.type = 'S4';
      this.mailParamsForSend.WorkOrder = itemBig.union_order;
      // this.mailParamsForSend.factory = item.factory;
      this.mailParamsForSend.name = itemBig.name;
      this.mailParamsForSend.machine_type = itemBig.machine_type;
      // this.mailParamsForSend.quantity = item.quatity;
      // this.mailParamsForSend.toolway = item.toolway;
      // this.mailParamsForSend.delivery_date = item.delivery_date;      
    } else {
      alert("該工件未停止計時")
    }
  }

  //取消送出
  handleSendCancel() {
    this.isSendVisible = false;
  }

  //确认送出
  sendOk() {
    if (this.paigongdanLiist['dbjz'] !== '' && this.paigongdanLiist['zjbs'] !== '' && this.paigongdanLiist['cncsj'] !== '' && this.paigongdanLiist['box'] !== '') {
      this.isSendOkLoading = true;
      this.isSendVisible = false;
      this.isSendOkLoading = false;
      if (this.xh) {
        console.log("重点")
        if (this.zdcc) {
          this.axios.axiosPost("UpdateUnionOrder2", { 'unionorder': this.unionorder, "name1": "stage", "newValue1": 3, "stageValue": 1 }).then((data) => {
            console.log(data, "工单状态修改成功了,增加了品鉴的状态")
          })
          this.axios.axiosPost('UpdateWorkOrder', {
            'unionorder': this.unionorder, 'workorder': this.workerName, id: this.paigongdanLiist['id'],
            'status': 3, "check_date": ""
          })
            .then((data) => {
              console.log(data)
              if (data['result'] === 'ok') {
                this.axios.axiosPost('QueryWorkOrder', { 'unionorder': this.unionorder, "type": 1, "status": 2 }).then((data) => {
                  if (!data["order"] || data["order"].length <= 0) {
                    this.axios.axiosPost("UpdateUnionOrder2", { 'unionorder': this.unionorder, "name1": "stage", "newValue1": 2, "stageValue": 0, "newValue12": 3, "stageValue2": 1 }).then((data) => {
                      console.log(data, "工单状态修改成功了,取消了当前工单状态")
                      location.reload();
                    })
                  } else {
                    console.log(data, "工件状态修改成功了,刷新当前工件状态")
                    console.log(this.wor)
                    this.axios.axiosPost("QueryCncDataSubOrder", { "unionorder": this.unionorder, "workorder": this.workerName, status: 2 }).then((data) => {
                      console.log(data);
                      if (data["result"] == "ok") {
                        console.log(data["result"])
                        console.log(data)
                        if (data["order"] == undefined || data["order"].length <= 0) {
                          this.QueryWorkOrder(this.wor);
                        } else {
                          this.QueryWorkOrder2(this.paigongdanLiist, this.wor, this.fdkey)
                        }
                      }
                    })
                  }
                })
                

              // 发送邮件
              this.axios.axiosPost('SendEmail', this.mailParamsForSend).then((data) => {
                if (data['result'] === 'ok') {
                  console.log("SendEmailSuccessfully!");
                }
              }).finally(() => {
                // 每次指定完毕后，重置数组，避免影响下次指定
                this.engineerJobNo = []
                this.engineerMail = []
              })
                
              }
            })
            .catch((err) => {
              console.log(err);
            })


        } else {
          this.axios.axiosPost("UpdateUnionOrder2", { 'unionorder': this.unionorder, "name1": "stage", "newValue1": 4, "stageValue": 1 }).then((data) => {
            console.log(data, "工单状态修改成功了,增加了品鉴的状态")
          })
          this.axios.axiosPost('UpdateWorkOrder', {
            'unionorder': this.unionorder, 'workorder': this.workerName, id: this.paigongdanLiist['id'],
            'status': 4, "machine_end_date_2": ""
          }).then((data) => {
            console.log(data)
            if (data['result'] === 'ok') {
              this.axios.axiosPost('QueryWorkOrder', { 'unionorder': this.unionorder, "type": 1, "status": 2 }).then((data) => {
                if (!data["order"] || data["order"].length <= 0) {
                  this.axios.axiosPost("UpdateUnionOrder2", { 'unionorder': this.unionorder, "name1": "stage", "newValue1": 2, "stageValue": 0, "newValue12": 4, "stageValue2": 1 }).then((data) => {
                    console.log(data, "工单状态修改成功了,取消了当前工单状态")
                    location.reload();
                  })
                } else {
                  console.log(data, "工件状态修改成功了,刷新当前工件状态")
                  console.log(this.wor)
                  this.axios.axiosPost("QueryCncDataSubOrder", { "unionorder": this.unionorder, "workorder": this.workerName, status: 2 }).then((data) => {
                    console.log(data);
                    if (data["result"] == "ok") {
                      console.log(data["result"])
                      console.log(data)
                      if (data["order"] == undefined || data["order"].length <= 0) {
                        this.QueryWorkOrder(this.wor);
                      } else {
                        this.QueryWorkOrder2(this.paigongdanLiist, this.wor, this.fdkey)
                      }
                    }
                  })
                }
              })

            }
          })
            .catch((err) => {
              console.log(err);
            })
        }
      } else {
        alert("未指定箱號")
      }
    } else {
      alert('排工單信息未填完整');
      this.isSendOkLoading = true;
      this.isSendVisible = false;
      this.isSendOkLoading = false;
    }



  }
  //计时器
  setTime(timeIndex, timeDic) {
    // debugger
    console.log(1111111)
    this.hour = Math.floor(this.timeIndex / 3600);
    this.minutes = Math.floor((this.timeIndex - this.hour * 3600) / 60);
    this.seconds = this.timeIndex - this.hour * 3600 - this.minutes * 60;
    this.hour = this.hour < 10 ? "0" + this.hour : this.hour;
    this.minutes = this.minutes < 10 ? "0" + this.minutes : this.minutes;
    this.seconds = this.seconds < 10 ? "0" + this.seconds : this.seconds;
    this.timeIndex = this.timeIndex + 1;
    console.log(222222)
    const temptime = (this.hour + ":" + this.minutes + ":" + this.seconds).toString();
    console.log('temptime ==== \n', temptime);
    timeDic[this.unionKey].splice(this.smallKey, 1, temptime);
    console.log('水水水水水水水水水水水水  \n', timeDic);
  }

  btn_CNC(data) {
    console.log(data)
    const CNCnum = {};
    if (data == "All") {
      CNCnum['select'] = "";

    } else {
      // CNCnum['select'] = data.substring(0, 1);
      CNCnum['select'] = data.substring(0, data.indexOf("(") - 1);

    }
    CNCnum['from'] = "jg";
    console.log(CNCnum['select'])
    this.router.navigate(['/CNC', CNCnum]);
  }

  QueryWorkOrder2(a, b, c) {
    console.log("触发", a)
    this.axios.axiosPost("QueryCncDataSubOrder", { "unionorder": a.unionorder, "workorder": a.workorder, status: 2 }).then((data) => {
      console.log(data);
      if (data["result"] == "ok") {
        this.listfd[b][c] = data["order"];
      }
    })
  }
  addRemarkDelete() {
    console.log(this.dlyy);
    for (var i = 0; i < this.dlyy.length; i++) {
      if (this.dlyy[i].show == true) {
        this.dlyy[i].show == false;
        this.axios.axiosPost("DeleteBeizhuInfo", { name: this.dlyy[i].name }).then((data => {
          this.addRemark3(this.updateData)
        }))
      }
    }


  }
  addRemarkAdd() {
    this.addDlyy = true;

  }
  // 取消——添加————添加设计备注
  addRemarkAddCancel() {
    this.addDlyy = false;
  }
  // 确定——添加————添加设计备注
  addRemarkAddOk() {
    this.addDlyy = false;
    this.axios.axiosPost("AddBeizhuInfo", { name: this.dlyyadd })
      .then((data) => {
        console.log(data);
        if (data['result'] === 'ok') {
          this.addRemark3(this.updateData);
        }
      })
      .catch((err) => {
        console.log(err);
      });
    this.addRemarkAddCancel()
    this.dlyyadd = ""
  }
}

